﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using DynSim.EntityFramework;
using DynSim.Basics;
using ProjectMercury;

namespace DynSim.Entities
{
    [Serializable]
    public class BasicParticle : IEntity, IMoveable, IHideable
    {
        public string name { get; set; }

        ParticleEffectManager manager;

        public ParticleEffect particle;
        public Vector3 position { get; set; }
        BaseEngine engine;

        public bool show = true;

        ProjectMercury.Renderers.Renderer render;

        Game game;

        public BasicParticle(Vector3 position, BaseEngine engine, string assetName, Game game, string name)
        {
            this.name = name;

            this.render = new ProjectMercury.Renderers.SpriteBatchRenderer();
            this.render.GraphicsDeviceService = engine.graphics;
            this.manager = new ParticleEffectManager(render);
            this.particle = game.Content.Load<ParticleEffect>(assetName);
            this.position = position;
            this.engine = engine;
            this.game = game;
        }

        public void Draw(GameTime gameTime)
        {
            manager.Draw();
        }

        public void Initialize()
        {
            particle.LoadContent(game.Content);
            particle.Initialise();

            render.LoadContent(game.Content);

            manager.Add(particle);
        }

        public void Update(GameTime gameTime)
        {
            particle.Trigger(new Vector2(position.X, position.Y));

            manager.Update((float)gameTime.ElapsedGameTime.TotalSeconds, true);
        }

        public void Move(Vector3 position)
        {
            this.position = position;
        }

        public void Show()
        {
            show = true;
        }

        public void Hide()
        {
            show = false;
        }
    }
}
